#define _USE_MATH_DEFINES 
#include "Transform.h"
#include "SceneNode.h"
#include <cmath>

mtBEGIN(Transform)
	mtBASE(ECS::Component);
mtEND

Transform::Transform():
	_sceneNode(nullptr)
{

}

Transform::~Transform()
{

}

const Vector2& Transform::getPosition() const
{
	return _position;
}

void Transform::setPosition(const Vector2& position)
{
	_position = position;

	if (!_sceneNode)
		_sceneNode = getComponent<SceneNode>();

	if (_sceneNode)
		_sceneNode->setNodePosition(position * 100.0f);
}

float Transform::getRotation() const
{
	return _rotation;
}

void Transform::setRotation(float rotation)
{
	_rotation = rotation;

	if (!_sceneNode)
		_sceneNode = getComponent<SceneNode>();

	if (_sceneNode)
		_sceneNode->setNodeRotation(rotation);
}

void Transform::setRotation( const Vector2& direction )
{
	auto angle = atan2f(direction.y, direction.x);
	setRotation(angle);
}

float Transform::getScale() const
{
	return _scale;
}

void Transform::setScale(float scale)
{
	_scale = scale;

	if (!_sceneNode)
		_sceneNode = getComponent<SceneNode>();

	if (_sceneNode)
		_sceneNode->setNodeScale(scale);
}

void Transform::scale(float scale)
{
	setScale(scale * _scale);
}